package com.wdd.libbase.base

import android.content.Context
import android.os.Bundle
import android.view.View
import com.wdd.libbase.mvp.IPresenter
import dagger.android.support.AndroidSupportInjection
import javax.inject.Inject

/**
 *
 * @ProjectName:    OwnTool
 * @Package:        com.wdd.libbase.base
 * @ClassName:      BaseMvpFragment
 * @Description:     mvp架构的fragment
 * @Author:         王丹丹
 * @CreateDate:     2019/12/10 18:56
 * @UpdateUser:     更新者
 * @UpdateDate:     2019/12/10 18:56
 * @UpdateRemark:   更新说明
 * @Version:        1.0
 */
abstract class BaseMvpFragment<P : IPresenter> : BaseFragment() {
    @Inject
    lateinit var mPresenter: P

    override fun onAttach(context: Context) {
        super.onAttach(context)
        AndroidSupportInjection.inject(this)
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        initLifecycleObserver()
        super.onViewCreated(view, savedInstanceState)
    }


    /**
     * 把mPresenter和activity生命周期绑定，要在initData之前
     */
    protected open fun initLifecycleObserver() {
        mPresenter.setLifecycleOwner(this)
        lifecycle.addObserver(mPresenter)
    }
}